package cn.bookshare.order.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.bookshare.order.vo.Order;

/**
 * 订单模块持久层代码
 * @author Lijt
 * @version 2017-2-23 下午2:34:09
 */
public class OrderDao extends HibernateDaoSupport{

	//订单保存
	public void save(Order order) {
		this.getHibernateTemplate().save(order);
	}

	//根据借出者查询订单
	public List<Order> findOrderByFuid(Integer fuid) {
		String hql = "select from Orders where fuid = ?";
		List<Order> list = this.getHibernateTemplate().find(hql, fuid);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	//根据借书者查询订单
	public List<Order> findOrderByTuid(Integer tuid) {
		String hql = "select from Orders where tuid = ?";
		List<Order> list = this.getHibernateTemplate().find(hql, tuid);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}
	
	//查询自己当前订单
	public List<Order> findOrderById(Integer id) {
		String hql = "select from Orders where tuid = ? or fuid = ?";
		List<Order> list = this.getHibernateTemplate().find(hql, id);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}
}
